package com.tth.learn.addproperties.java;

import org.junit.Test;

/**
 * 静态代理类
 * @Author tth
 * @Date 2022/12/30 14:29
 */
public class StaticProxyTest {

    @Test
    public void test() {
        // 创建被代理类对象
        NikeClothFactory nike = new NikeClothFactory();
        // 创建代理类对象
        ProxyClothFactory proxyClothFactory = new ProxyClothFactory(nike);
        // 开始生产服装
        proxyClothFactory.produceCloth();
    }
}

/**
 * 服装工厂接口：定义生产衣服的接口
 */
interface ClothFactory {

    void produceCloth();
}

/**
 * 代理类：服装代理加工厂
 */
class ProxyClothFactory implements ClothFactory {

    private ClothFactory clothFactory;

    public ProxyClothFactory(ClothFactory clothFactory) {
        this.clothFactory = clothFactory;
    }

    @Override
    public void produceCloth() {
        System.out.println("服装代理加工厂开始进行一些准备工作");
        clothFactory.produceCloth();
        System.out.println("服装代理加工厂开始进行收尾工作");
    }
}

/**
 * 被代理类
 */
class NikeClothFactory implements ClothFactory {
    @Override
    public void produceCloth() {
        System.out.println("Nike服装加工厂生产一批运动服");
    }
}

